{% extends "layout.html" %}
{% block content %}
    <div class="x-nav">
      <div class="layui-col-md6">
          <button class="layui-btn" onclick="x_admin_show('添加过滤器','channel-data-filter-edit.html?channel_id='+channel_id,800,400)"><i class="layui-icon"></i>添加过滤器</button>
      </div>
      <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);" title="刷新">
        <i class="layui-icon" style="line-height:30px">ဂ</i></a>
    </div>
    <div class="x-body layui-anim layui-anim-up">
      <table id="channel_data_filter_list" class="layui-table" lay-filter="channel">
      </table>
      <script type="text/html" id="channelBar">
        <div class="layui-btn-group">
          <button type="button" class="layui-btn layui-btn-sm" lay-event="edit"><i class="layui-icon">&#xe642;</i></button>
          <button type="button" class="layui-btn layui-btn-sm"lay-event="del"><i class="layui-icon">&#xe640;</i></button>
        </div>
      </script>    
</div>
    <script>
      var channel_id=GetQueryString('channel_id');
      $(function  () {
            layui.use(['table','form'], function(){
                var table = layui.table;
                var layer=layui.layer;
                table.render({
                    elem: '#channel_data_filter_list'
                    ,height:'full-100'
                    ,url:'./channel_data_filter_data_list?channel_id='+channel_id
                    ,cols:[[
                        {type:'checkbox', fixed: 'left'}
                        ,{title:'ID',field:'channel_data_filter_id',align: 'center', sort: true, fixed: true}
                        ,{title:'主机IP',field:'host_ip',align: 'center'}
                        ,{title:'端口号',field:'port',align: 'center', sort: true,templet:function(d){
                            if(d.channel_id!=1)
                                return d.port
                            else
                                return "-"
                        }}
                        ,{title:'过滤器',field:'filter',align: 'center'}
                        ,{fixed: 'right', align:'center', toolbar: '#channelBar'}
                    ]]
                    ,page: true
                });
                //监听表格复选框选择
                table.on('checkbox(channel)', function(obj){
                });
                //监听工具条
                table.on('tool(channel)', function(obj){
                    var data = obj.data;
                    switch(obj.event){
                        case 'edit':
                            x_admin_show('编辑通道','channel-data-filter-edit.html?channel_id='+channel_id+'&channel_data_filter_id='+obj.data.channel_data_filter_id,800,400);
                            break;
                        case 'del':
                            if(obj.data.channel_id==1){
                                layer.alert("默认通道不可删除！");
                                return;
                            }
                            layer.confirm('真的删除行么', function(index){
                                // console.log(obj.data);
                                data={'channel_data_filter_id':obj.data.channel_data_filter_id};
                                $.ajax({
                                    url:'del_channel_data_filter',
                                    type:'POST',
                                    data:data,
                                    success:function(data){
                                        // console.log(data);
                                        if(data.code==0)obj.del();
                                    }
                                });
                                obj.del();
                                layer.close(index);
                            });
                            break;
                        default:
                    }
                });
            });
        })
    </script>
{% endblock %}